package com.zhentao.controller;

import com.zhentao.pojo.ApUserSearch;
import com.zhentao.repository.UserRecordRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserRecordController {
    @Autowired
    private UserRecordRepository repository;

    // 添加用户记录
    @PostMapping("/add")
    public ApUserSearch add(@RequestBody ApUserSearch userRecord) {
        userRecord.setCreatedTime(new Date());
        userRecord.set_class("com.zhentao.entity.UserRecord");
        return repository.save(userRecord);
    }

    // 删除用户记录（按userId）
    @DeleteMapping("/delete/{userId}")
    public void deleteByUserId(@PathVariable String userId) {
        ApUserSearch user = repository.findByUserId(userId);
        if (user != null) {
            repository.delete(user);
        }
    }

    // 查询所有历史记录
    @GetMapping("/list")
    public List<ApUserSearch> list() {
        return repository.findAll();
    }
} 